package com.example.basecommon.http.rxjava;

import com.trello.rxlifecycle2.components.support.RxFragment;

import io.reactivex.Observer;
/**
 * @author dlj
 * rx框架使用示例
 */
public class RequestDemo {

    /**
     * Get 请求BaseResponse
     * @param context
     * @param observer
     */
//    public static void getUser(RxActivity context, MyObserver<BaseResponse> observer){
//        HttpUtils.request()
//                .getUser().compose(RxHelper.observableIO2Main(context))
//                .subscribe(observer);
//    }

    /**
     * Get 请求BaseResponse
     * @param context
     * @param observer
     */
//    public static void getUserList(RxActivity context, MyObserver<List<BaseResponse>> observer){
//        HttpUtils.request()
//                .getUser().compose(RxHelper.observableIO2Main(context))
//                .subscribe(observer);
//    }
    /**
     * Post 请求BaseResponse
     * @param context
     * @param consumer
     */
//    public static void postBaseResponse(RxAppCompatActivity context, BaseResponse name, BaseResponse password, Observer<BaseResponse> consumer){
//        HttpUtils.request()
//                .postUser(name,password).compose(RxHelper.observableIO2Main(context))
//                .subscribe(consumer);
//    }
    /**
     * Put 请求BaseResponse
     * @param context
     * @param consumer
     */
//    public static void putBaseResponse(RxFragment context, String access_token, Observer<BaseResponse> consumer){
//        Map<String, String> headers = new HashMap<String, String>();
//        headers.put("Accept","application/json");
//        headers.put("Authorization",access_token);
//        HttpUtils.request()
//                .postUser(headers).compose(RxHelper.observableIO2Main(context))
//                .subscribe(consumer);
//    }
    /**
     * Delete 请求BaseResponse
     * @param context
     * @param consumer
     */
//    public static void deleteBaseResponse(RxFragment context, BaseResponse access_token, Observer<BaseResponse> consumer){
//        HttpUtils.request()
//                .delete(access_token,1).compose(RxHelper.observableIO2Main(context))
//                .subscribe(consumer);
//    }

    /**
     * 上传图片
     * @param context
     * @param observer
     */
    public static void upImagView(RxFragment context, BaseResponse  access_token, BaseResponse str, Observer<BaseResponse> observer){
//        File file = new File(str);
////        File file = new File(imgPath);
//        Map<BaseResponse,BaseResponse> header = new HashMap<BaseResponse, BaseResponse>();
//        header.put("Accept","application/json");
//        header.put("Authorization",access_token);
////        File file =new File(filePath);
//        RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file);
////        RequestBody requestFile =
////                RequestBody.create(MediaType.parse("multipart/form-data"), file);
//        MultipartBody.Part body =
//                MultipartBody.Part.createFormData("file", file.getName(), reqFile);
//        HttpUtils.request().uploadImage(header,body).compose(RxHelper.observableIO2Main(context))
//                .subscribe(observer);
    }

    /**
     * 上传多张图片
     * @param files
     */
//    public static void upLoadImg(RxFragment context, BaseResponse access_token, List<File> files, Observer<BaseResponse> observer1){
//        Map<BaseResponse,BaseResponse> header = new HashMap<BaseResponse, BaseResponse>();
//        header.put("Accept","application/json");
//        header.put("Authorization",access_token);
//        MultipartBody.Builder builder = new MultipartBody.Builder()
//                .setType(MultipartBody.FORM);//表单类型
//        for (int i = 0; i < files.size(); i++) {
//            File file = files.get(i);
//            RequestBody photoRequestBody = RequestBody.create(MediaType.parse("image/*"), file);
//            builder.addFormDataPart("file", file.getName(), photoRequestBody);
//        }
//        List<MultipartBody.Part> parts = builder.build().parts();
//        HttpUtils.request().uploadImage1(header,parts).compose(RxHelper.observableIO2Main(context))
//                .subscribe(observer1);
//    }
}

